package edu.bit.water.service;


import edu.bit.water.dao.TechProcessDao;
import edu.bit.water.entity.TechnicalIndicator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import java.util.*;

import edu.bit.water.entity.TechProcess;

/**
 * meta_assessment_indicator数据表对应的service类
 * @Author: Page
 */
@Service
public class TechProcessService {

    @Autowired
    private TechProcessDao TechProcessDao;

    public List<TechProcess> selectTechProcess(String companyId) {
        return TechProcessDao.selectTechProcess(companyId);
    }

    public List<TechProcess> selectAllTechProcess() {
        return TechProcessDao.selectAllTechProcess();
    }

    public Map<String, Object> insertTechProcess(TechProcess TechProcess) {
        Map<String, Object> result = new HashMap<>();
        Integer id = TechProcessDao.getMaxId();
        if (id != null) {
            TechProcess.setId(id + 1);
        }
        int tmp = TechProcessDao.insertTechProcess(TechProcess);
        if (tmp == 1) {
            result.put("status", "success");
        }
        else {
            result.put("status", "failed");
        }
        return result;
    }

    public Map<String, Object> deleteTechProcess(List<String> ids) {
        Map<String, Object> result = new HashMap<>();
        boolean flag = true;
        for (int i = 0; i < ids.size(); i++) {
            int temp = TechProcessDao.deleteChartByBusiness(Integer.parseInt(ids.get(i)));
            int tmp = TechProcessDao.deleteTechProcess(Integer.parseInt(ids.get(i)));
            if (tmp == 1) {
                result.put(ids.get(i).toString(), "success");
            }
            else {
                result.put(ids.get(i).toString(), "failed");
                flag = false;
            }
        }
        if (flag) {
            result.put("status", "success");
        }
        else {
            result.put("status", "failed");
        }
        return result;
    }


    public Map<String, Object> updateTechProcess(TechProcess TechProcess) {
        Map<String, Object> result = new HashMap<>();
        int tmp = TechProcessDao.updateTechProcess(TechProcess);
        if(tmp == 1) {
            result.put("status", "success");
        }
        else {
            result.put("status", "failed");
        }
        return result;
    }

    public int getLidByCid(int cid){
        int result = TechProcessDao.getLidByCid(cid);
        return result;
    }
}